package com.example.learn_gl_android.model

import com.example.learn_gl_android.anglib.util.MyGLUtil
import java.nio.FloatBuffer
import kotlin.math.cos
import kotlin.math.sin

class SixPointedStar {
    var mAngleX : Float = 0.0f
    var mAngleY : Float = 0.0f
    val M_UNIT_SiZE = 1


    fun initVertexData(R : Float ,r : Float ,z : Float){
        var mVertexCount : Int = 0
        var mVertexBuffer : FloatBuffer
        var mColorBuffer : FloatBuffer

        val mFirst = ArrayList<Float>()
        val mAngleInterval = 360/6

        for (mAngle in 0 until 360 step mAngleInterval){
            mFirst.add(0f,);mFirst.add(0f);mFirst.add(0f) // Fist Corner Point

            // First Corner
            mFirst.add((R*M_UNIT_SiZE* cos(Math.toRadians(mAngle.toDouble()))).toFloat())
            mFirst.add((R*M_UNIT_SiZE* sin(Math.toRadians(mAngle.toDouble()))).toFloat())
            mFirst.add(z)

            // Second Corner
            mFirst.add((R*M_UNIT_SiZE* cos(Math.toRadians(mAngle.toDouble() + mAngleInterval/2))).toFloat())
            mFirst.add((R*M_UNIT_SiZE* sin(Math.toRadians(mAngle.toDouble() + mAngleInterval/2))).toFloat())
            mFirst.add(z)

            // Third Corner
            mFirst.add((R*M_UNIT_SiZE* cos(Math.toRadians(mAngle.toDouble() + mAngleInterval))).toFloat())
            mFirst.add((R*M_UNIT_SiZE* sin(Math.toRadians(mAngle.toDouble() + mAngleInterval))).toFloat())
            mFirst.add(z)

            mVertexCount = mFirst.size/3

            val vertexArray : FloatArray = mFirst.toFloatArray()
            mVertexBuffer = MyGLUtil.initFloatBuffer(vertexArray)

            val colorArray = FloatArray(mVertexCount * 4)
            for (i in 0 until mVertexCount){
                if (i % 3 == 0) {
                    colorArray[i*4] = 1f
                    colorArray[i*4+1] = 1f
                    colorArray[i*4+2] = 1f
                    colorArray[i*4+3] = 0f
                }else{
                    colorArray[i*4] = 0.45f
                    colorArray[i*4+1] = 0.75f
                    colorArray[i*4+2] = 0.75f
                    colorArray[i*4+3] = 0f
                }
            }
            mColorBuffer = MyGLUtil.initFloatBuffer(colorArray)
        }
    }
    fun initShader(){

    }

    fun drawSelf(){

    }

}